package com.dnui.seven2.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dnui.seven2.common.R;
import com.dnui.seven2.entity.Employee;
import com.dnui.seven2.entity.Feedback;
import com.dnui.seven2.entity.Merch;
import com.dnui.seven2.service.FeedbackService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/feedback")
public class FeedbackController {
    @Autowired
    private FeedbackService feedbackService;


    @PostMapping("saveFeedback")
    public R<String> saveFeedback(@RequestBody Feedback feedback){
        feedbackService.save(feedback);
        return  R.success("添加成功");
    }

    @DeleteMapping("deleteFeedback/feedbackId}")
    public R<String> deleteFeedback( @PathVariable Long feedbackId){
        feedbackService.deleteFeedback(feedbackId);
        return  R.success("删除成功");
    }

    @PutMapping("updateFeedback")
    public R<String> updateFeedback(@RequestBody Feedback feedback){
        feedbackService.updateFeedback(feedback);
        return  R.success("修改成功");
    }

    @GetMapping("queryById/{feedbackId}")
    public R<Feedback> queryById(@PathVariable Long feedbackId){
        Feedback feedback= feedbackService.getById(feedbackId);
        return  R.success(feedback);
    }


    @GetMapping("/queryFeedbacks")
    public R<Page> queryFeedbacks(@PathVariable Integer currentPageNum,@PathVariable Integer everyPage ){
        //构造分页构造器
        Page pageInfo=new Page(currentPageNum,everyPage);
        //构造条件构造器
        LambdaQueryWrapper<Feedback> queryWrapper=new LambdaQueryWrapper();

        //执行查询
        feedbackService.page(pageInfo,queryWrapper);
        return R.success(pageInfo);
    }

    @GetMapping("/selectAll")
    public R<List<Feedback>> selectAll(){
        List<Feedback> feedbacks = feedbackService.selectAll();
        return  R.success(feedbacks);
    }
}
